package org.omg.GIOP;

//
// Helper class for : TargetAddress
//
// @author OpenORB Compiler
//
public class TargetAddressHelper {

	//
	// Insert TargetAddress into an any
	// @param a an any
	// @param t TargetAddress value
	//
	public static void insert(org.omg.CORBA.Any a, org.omg.GIOP.TargetAddress t) {
		a.insert_Streamable(new org.omg.GIOP.TargetAddressHolder(t));
	}

	//
	// Extract TargetAddress from an any
	// @param a an any
	// @return the extracted TargetAddress value
	//
	public static org.omg.GIOP.TargetAddress extract(org.omg.CORBA.Any a) {
		return read(a.create_input_stream());
	}

	//
	// Internal TypeCode value
	//
	private static org.omg.CORBA.TypeCode _tc = null;
	private static boolean _working = false;

	//
	// Return the TargetAddress TypeCode
	// @return a TypeCode
	//
	public static org.omg.CORBA.TypeCode type() {
		if (_tc == null) {
			synchronized (org.omg.CORBA.TypeCode.class) {
				if (_tc != null)
					return _tc;
				if (_working)
					return org.omg.CORBA.ORB.init().create_recursive_tc(id());
				_working = true;
				org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
				org.omg.CORBA.UnionMember[] _members = new org.omg.CORBA.UnionMember[3];
				org.omg.CORBA.Any any;

				any = orb.create_any();
				org.omg.GIOP.AddressingDispositionHelper.insert(any,
						(short) (org.omg.GIOP.KeyAddr.value));
				_members[0] = new org.omg.CORBA.UnionMember();
				_members[0].name = "object_key";
				_members[0].label = any;
				_members[0].type = org.omg.GIOP.OctetSeqHelper.type();
				any = orb.create_any();
				org.omg.GIOP.AddressingDispositionHelper.insert(any,
						(short) (org.omg.GIOP.ProfileAddr.value));
				_members[1] = new org.omg.CORBA.UnionMember();
				_members[1].name = "profile";
				_members[1].label = any;
				_members[1].type = org.omg.IOP.TaggedProfileHelper.type();
				any = orb.create_any();
				org.omg.GIOP.AddressingDispositionHelper.insert(any,
						(short) (org.omg.GIOP.ReferenceAddr.value));
				_members[2] = new org.omg.CORBA.UnionMember();
				_members[2].name = "ior";
				_members[2].label = any;
				_members[2].type = org.omg.GIOP.IORAddressingInfoHelper.type();
				_tc = orb.create_union_tc(id(), "TargetAddress",
						org.omg.GIOP.AddressingDispositionHelper.type(),
						_members);
				_working = false;
			}
		}
		return _tc;
	}

	//
	// Return the TargetAddress IDL ID
	// @return an ID
	//
	public static String id() {
		return _id;
	}

	private final static String _id = "IDL:omg.org/GIOP/TargetAddress:1.0";

	//
	// Read TargetAddress from a marshalled stream
	// @param istream the input stream
	// @return the readed TargetAddress value
	//
	public static org.omg.GIOP.TargetAddress read(
			org.omg.CORBA.portable.InputStream istream) {
		org.omg.GIOP.TargetAddress new_one = new org.omg.GIOP.TargetAddress();

		new_one.__d = org.omg.GIOP.AddressingDispositionHelper.read(istream);
		if (new_one.__d == (short) org.omg.GIOP.KeyAddr.value) {
			new_one._object_key = org.omg.GIOP.OctetSeqHelper.read(istream);
		} else if (new_one.__d == (short) org.omg.GIOP.ProfileAddr.value) {
			new_one._profile = org.omg.IOP.TaggedProfileHelper.read(istream);
		} else if (new_one.__d == (short) org.omg.GIOP.ReferenceAddr.value) {
			new_one._ior = org.omg.GIOP.IORAddressingInfoHelper.read(istream);
		}

		return new_one;
	}

	//
	// Write TargetAddress into a marshalled stream
	// @param ostream the output stream
	// @param value TargetAddress value
	//
	public static void write(org.omg.CORBA.portable.OutputStream ostream,
			org.omg.GIOP.TargetAddress value) {
		org.omg.GIOP.AddressingDispositionHelper.write(ostream, value.__d);
		if (value.__d == (short) org.omg.GIOP.KeyAddr.value) {
			org.omg.GIOP.OctetSeqHelper.write(ostream, value._object_key);
		} else if (value.__d == (short) org.omg.GIOP.ProfileAddr.value) {
			org.omg.IOP.TaggedProfileHelper.write(ostream, value._profile);
		} else if (value.__d == (short) org.omg.GIOP.ReferenceAddr.value) {
			org.omg.GIOP.IORAddressingInfoHelper.write(ostream, value._ior);
		}
	}

}
